import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import defineOptions from 'unplugin-vue-define-options/vite'
const { resolve } = require('path') //必须要引入resolve

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue({
        script: { refSugar: true },
        reactivityTransform: false,
        template: {
          compilerOptions: {
            runtimeCompiler: true,
          }
        }
      }),
      defineOptions(),
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
        '@Assets': resolve(__dirname, 'src/assets'),
        '@Images': resolve(__dirname, 'src/assets/images'),
        '@Components': resolve(__dirname, 'src/views/components'),
        '@Pages': resolve(__dirname, 'src/views/pages'),
        '@Utils': resolve(__dirname, 'src/views/utils'),
      },
    },
    build: {
      rollupOptions: {
        miniify: 'terser',
        terserOptions: {
          compress: {
            drop_console: false,
            drop_debugger: false,
          },
        },
      },
    },
    server: {
      host: env.VITE_MODE_DOMAIN,
      port: '8001',
    },
  }
})
